this.name					= "probeMissile";
this.author					= "Thargoid & Eric Walch";
this.copyright				= "Creative Commons: attribution, non-commercial, sharealike.";
this.description				= "Operation and pick-up of probe missile.";
this.version				= "1.01";

this.shipWasScooped = function(scooper)
	{
	this.versionCheck();
	if(scooper == player || scooper == player.ship)
		{
		player.consoleMessage("Probe missile recovered, refuelled and ready for re-use.", 6);
		this.thePlayerShip.awardEquipment("EQ_PROBE_LAUNCHER_MINE")
		}
	}

this.doScan = function() 
	{ 
	this.versionCheck();

	// create an array with all ships ("isShip" includes barrels and rock etc.) 
	function allShips(entity) {return entity.isShip}; 
	let anyShips = system.filteredEntities(this, allShips, this.ship, 25600); 

	// do neutral ships 
	function neutralShips(entity) {return entity.scanClass == "CLASS_NEUTRAL"}; 
	this.neutralCount = anyShips.filter(neutralShips).length; 

	// do police/military ships 
	function policeShips(entity) {return (entity.scanClass == "CLASS_POLICE" || entity.scanClass == "CLASS_MILITARY")}; 
	this.policeCount = anyShips.filter(policeShips).length; 

	// do thargoid ships 
	function thargoidShips(entity) {return entity.scanClass == "CLASS_THARGOID"}; 
	this.thargoidCount = anyShips.filter(thargoidShips).length; 

	// do rocks 
	function rockShips(entity) {return entity.scanClass == "CLASS_ROCK" && !entity.isStation}; 
	this.rockCount = anyShips.filter(rockShips).length; 

	// do stations 
	function stationShips(entity) {return (entity.scanClass == "CLASS_STATION" || entity.isStation)}; 
	this.stationCount = anyShips.filter(stationShips).length; 

	// do cargo 
	function cargoShips(entity) {return entity.scanClass == "CLASS_CARGO"}; 
	this.cargoCount = anyShips.filter(cargoShips).length; 

	// do trader ships 
	function isPirateVictim(entity) {return entity.isPirateVictim}; 
	this.traderCount = anyShips.filter(isPirateVictim).length; 

	// do trader escorts 
	function isTraderEscort(entity) {return entity.primaryRole == "escort" && entity.owner && entity.owner.isPirateVictim}; 
	this.traderEscortCount = anyShips.filter(isTraderEscort).length; 

	// do pirate ships 
	function isPirate(entity) {return entity.isPirate}; 
	this.pirateCount = anyShips.filter(isPirate).length; 

	// do pirate escorts 
	function isPirateEscort(entity) {return entity.primaryRole == "escort" && entity.owner && entity.owner.isPirate}; 
	this.pirateEscortCount = anyShips.filter(isPirateEscort).length; 

	this.totalCount = this.neutralCount + this.policeCount + this.thargoidCount + this.rockCount + this.stationCount + this.cargoCount; 
	if(this.totalCount == 0) 
		{ 
		player.commsMessage("Probe Missile - Nothing within scanner range.", 6); 
		} 
	else
		{ 
		player.commsMessage("Scan readout :", 6); 
		if(this.traderCount+this.traderEscortCount > 0) player.commsMessage("Traders - " + this.traderCount + " (with " + this.traderEscortCount + " escorts)", 6); 

		if(this.policeCount > 0) player.commsMessage("System vessels - " + this.policeCount, 6); 
		if(this.pirateCount+this.pirateEscortCount > 0) player.commsMessage("Pirates - " + this.pirateCount + " (with " + this.pirateEscortCount + " escorts)", 6); 
		if(this.thargoidCount > 0) player.commsMessage("Aliens - " + this.thargoidCount, 6); 
		if(this.rockCount > 0) player.commsMessage("Asteroids - " + this.rockCount, 6); 
		if(this.cargoCount > 0) player.commsMessage("Loose Cargo - " + this.cargoCount, 6);
		if(this.stationCount > 0) player.commsMessage("Stations - " + this.stationCount, 6); 
		let otherShipsCount = this.neutralCount - this.pirateCount - this.pirateEscortCount - this.traderCount - this.traderEscortCount; 
		if(otherShipsCount > 0) player.commsMessage("Other ships - " + otherShipsCount, 6); 
		} 
	}

this.shipDied = function()
	{
	player.consoleMessage("Contact lost with probe missile.", 6);
	}

this.probeLaunched = function()
	{
	player.consoleMessage("Probe missile launch successful.", 6);
	}

this.probeReturning = function()
	{
	player.commsMessage("Probe Missile - Returning, please slow for rendezvous.", 6);
	}

this.probeLost = function()
	{
	player.commsMessage("Probe Missile - Unable to reach ship for rendezvous, shutting down.", 6);
	}

this.getPlayer = function()
	{
	this.versionCheck();
	this.ship.target = this.thePlayerShip; 
	}

this.versionCheck = function()
	{
	if (0 < oolite.compareVersion("1.72")) 
		{ 
		// 1.71.x or earlier 
		this.thePlayerShip = player; 
		} 
	else 
		{ 
		// 1.72 or later 
		this.thePlayerShip = player.ship; 
		}
	}

